<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>相交链表算法解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        :root {
            --primary: #4F46E5;
            --primary-light: #818CF8;
            --accent: #10B981;
            --dark: #1F2937;
            --light: #F9FAFB;
        }
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: var(--dark);
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
            color: white;
        }
        .code-block {
            background-color: #2D2D2D;
            color: #F8F8F2;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(79, 70, 229, 0.2);
            z-index: -1;
            transition: height 0.3s ease;
        }
        .highlight:hover::after {
            height: 100%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero py-20 px-6 md:px-12 lg:px-24">
        <div class="container mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold mb-6 leading-tight">相交链表算法解析</h1>
                    <p class="text-xl md:text-2xl opacity-90 mb-8">探索双指针在链表问题中的精妙应用</p>
                    <div class="flex items-center space-x-4">
                        <span class="px-4 py-2 bg-white text-primary rounded-full font-medium">#算法</span>
                        <span class="px-4 py-2 bg-white text-primary rounded-full font-medium">#数据结构</span>
                        <span class="px-4 py-2 bg-white text-primary rounded-full font-medium">#双指针</span>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="mermaid">
                        graph LR
                            A[链表A] -->|节点1| B[节点2]
                            B --> C[节点3]
                            C --> D[相交节点]
                            E[链表B] -->|节点a| F[节点b]
                            F --> D
                            D --> G[节点4]
                            G --> H[节点5]
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 md:px-12 lg:px-24 py-16">
        <!-- Problem Description -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-primary flex items-center justify-center mr-4">
                    <i class="fas fa-question text-white text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">题目描述</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-8 card">
                <p class="text-lg mb-6">找出两个单链表相交的起始节点。如果两个链表不存在相交节点，返回 <code class="bg-gray-100 px-2 py-1 rounded">null</code>。</p>
                
                <div class="border-l-4 border-primary pl-4 mb-6">
                    <p class="text-gray-600"><i class="fas fa-info-circle text-primary mr-2"></i> <strong>注意事项：</strong></p>
                    <ul class="list-disc pl-5 space-y-2">
                        <li>链表中的节点数目范围在 <code class="bg-gray-100 px-2 py-1 rounded">[0, 10^4]</code> 内</li>
                        <li>相交的意思是两个链表的尾部共享相同的节点</li>
                        <li>题目数据保证不存在环</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Core Algorithm -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-accent flex items-center justify-center mr-4">
                    <i class="fas fa-brain text-white text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">核心考点与算法</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-8 card">
                <h3 class="text-2xl font-bold mb-4 text-primary flex items-center">
                    <i class="fas fa-hand-point-right mr-3"></i> 双指针法
                </h3>
                <p class="text-lg mb-6">双指针技巧在解决链表问题时非常高效，特别是当我们需要同时遍历两个链表时。这种方法的精妙之处在于它巧妙地利用了链表长度的差异。</p>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h4 class="text-xl font-semibold mb-4 highlight">解题思路</h4>
                        <p class="mb-4">让两个指针分别从两个链表头开始走，当一个指针到达末尾时，切换到另一个链表头继续走。若有交点，两指针会在交点处相遇。</p>
                        <p class="font-medium">这种方法的优点：</p>
                        <ul class="list-disc pl-5 space-y-2 mt-2">
                            <li>时间复杂度：<code class="bg-gray-100 px-2 py-1 rounded">O(n + m)</code></li>
                            <li>空间复杂度：<code class="bg-gray-100 px-2 py-1 rounded">O(1)</code></li>
                            <li>不需要额外的存储空间</li>
                            <li>处理不同长度的链表非常高效</li>
                        </ul>
                    </div>
                    <div>
                        <div class="mermaid">
                            flowchart TD
                                A[指针A在链表A] -->|遍历| B[到达链表A末尾]
                                B --> C[切换到链表B头部]
                                D[指针B在链表B] -->|遍历| E[到达链表B末尾]
                                E --> F[切换到链表A头部]
                                C --> G[继续遍历]
                                F --> G
                                G --> H{相遇?}
                                H -->|是| I[找到交点]
                                H -->|否| G
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Example Code -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-purple-600 flex items-center justify-center mr-4">
                    <i class="fas fa-code text-white text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">示例代码</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="flex items-center bg-gray-800 px-4 py-3">
                    <div class="flex space-x-2 mr-4">
                        <span class="w-3 h-3 rounded-full bg-red-500"></span>
                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                        <span class="w-3 h-3 rounded-full bg-green-500"></span>
                    </div>
                    <span class="text-gray-300 text-sm">Python 实现</span>
                </div>
                <div class="code-block p-6">
                    <pre><code class="language-python">def getIntersectionNode(headA, headB):
    if not headA or not headB:
        return None
    pa, pb = headA, headB
    while pa != pb:
        pa = pa.next if pa else headB
        pb = pb.next if pb else headA
    return pa</code></pre>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section>
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-600 flex items-center justify-center mr-4">
                    <i class="fas fa-project-diagram text-white text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">算法可视化</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-8 card">
                <div class="mermaid">
                    sequenceDiagram
                        participant A as 指针A
                        participant B as 指针B
                        A->>A: 从链表A头开始
                        B->>B: 从链表B头开始
                        loop 遍历
                            A->>A: 移动到下一个节点
                            B->>B: 移动到下一个节点
                            alt 指针A到达末尾
                                A->>B: 切换到链表B头
                            end
                            alt 指针B到达末尾
                                B->>A: 切换到链表A头
                            end
                            A->>B: 检查是否相遇
                        end
                        A->>B: 在交点处相遇
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            sequence: {
                diagramMarginX: 50,
                diagramMarginY: 10,
                boxTextMargin: 5,
                noteMargin: 10,
                messageMargin: 35,
                mirrorActors: true
            }
        });
    </script>
</body>
</html>